package com.egao.oa.controller;

import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.oa.entity.CustomerOffer;
import com.egao.oa.entity.PhoneBook;
import com.egao.oa.service.CustomerOfferService;
import com.egao.oa.service.PhoneBookService;
import com.egao.sszg.entity.Customer;
import com.egao.sszg.service.SszgService;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 *
 * 客户报价
 * @author : Doman
 * @date : 2021-04-01 15:58:14
 * @version ：1.0
 */

@Controller
@RequestMapping("/oa/customerOffer")
public class CustomerOfferController extends BaseController {

	@Autowired
	private CustomerOfferService customerOfferService;
	@Autowired
	private SszgService sszgService;
    @Autowired
    private PhoneBookService phoneBookService;
	
	/**
	 * 页面
	 **/
	@RequiresPermissions("oa:customerOffer:view")
	@RequestMapping()
	public String view(Model model) {
        model.addAttribute("customersList",sszgService.list(new Customer(), getLoginUser()));
        PhoneBook phoneBook = new PhoneBook();
        phoneBook.setAutocompletevalue("it");
        model.addAttribute("itphoneBookList",phoneBookService.list(phoneBook, getLoginUser()));
	    return "oa/customerOffer.html";
	}

	/**
	 * 分页查询列表
	 */
	@RequiresPermissions("oa:customerOffer:list")
	@OperLog(value = "客户报价", desc = "分页查询")
	@ResponseBody
	@RequestMapping("/page")
    public JsonResult list(PageResult2<T> page, CustomerOffer customerOffer) throws Exception{
        return customerOfferService.list(page, customerOffer, getLoginUser());
    }

    /**
     * 查询全部客户报价
     */
    @RequiresPermissions("oa:customerOffer:list")
    @OperLog(value = "客户报价", desc = "查询全部")
    @ResponseBody
    @RequestMapping("/list")
    public JsonResult list(CustomerOffer customerOffer){
        return JsonResult.ok().setData(customerOfferService.list(customerOffer, getLoginUser()));
    }

    /**
     * 根据id查询客户报价
     */
    @RequiresPermissions("oa:customerOffer:list")
    @OperLog(value = "客户报价", desc = "根据id查询")
    @ResponseBody
    @RequestMapping("/get")
    public JsonResult get(CustomerOffer customerOffer) {
        return customerOfferService.getById(customerOffer);
		// 使用关联查询
        //PageParam<customerOffer> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<customerOffer> records = customerOfferService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加客户报价
     */
    @RequiresPermissions("oa:customerOffer:save")
    @OperLog(value = "客户报价", desc = "添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/save")
    public JsonResult save(Model model, CustomerOffer customerOffer) {
        return customerOfferService.save(customerOffer, getLoginUser());
    }

    /**
     * 修改客户报价
     */
    @RequiresPermissions("oa:customerOffer:update")
    @OperLog(value = "客户报价", desc = "修改", param = false, result = true)
    @ResponseBody
    @RequestMapping("/update")
    public JsonResult update(Model model, CustomerOffer customerOffer) {
        return customerOfferService.update(customerOffer, getLoginUser());
    }

    /**
     * 删除客户报价
     */
    @RequiresPermissions("oa:customerOffer:remove")
    @OperLog(value = "客户报价", desc = "删除", result = true)
    @ResponseBody
    @RequestMapping("/remove")
    public JsonResult remove(CustomerOffer customerOffer ) {
        return customerOfferService.remove(customerOffer, getLoginUser());
    }

    /**
     * 批量添加客户报价
     */
    /**@RequiresPermissions("oa:customerOffer:save")
    @OperLog(value = "客户报价", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<CustomerOffer> list) {
        if (customerOfferService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改客户报价
     */
    /**@RequiresPermissions("oa:customerOffer:update")
    @OperLog(value = "客户报价", desc = "批量修改", result = true)
    @ResponseBody
    @RequestMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<CustomerOffer> batchParam) {
        if (batchParam.update(customerOfferService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除客户报价
     */
    /**@RequiresPermissions("oa:customerOffer:remove")
    @OperLog(value = "客户报价", desc = "批量删除", result = true)
    @ResponseBody
    @RequestMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (customerOfferService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
